package com.zc.security.domain;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Collections;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class LoginUser implements UserDetails {
    private User user;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        //权限
        return Collections.emptyList();
    }

    @Override
    public String getPassword() {
        //密码
        return user.getPassword();
    }

    @Override
    public String getUsername() {
        //用户名
        return user.getUserName();
    }

    @Override
    public boolean isAccountNonExpired() {
        //是否没有过期
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        //是否没有被锁定
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        //密码是否没有过期
        return true;
    }

    @Override
    public boolean isEnabled() {
        //是否可用
        return user.getStatus() == 1;
    }
}
